import type { FilterItem } from '@/components/FilterBar/types'
import { getUserInfo, getFindDeviceTypeTree } from '@/api/eqpt/visual'
import { getResource } from '@/api/resource'
import { ref, reactive } from 'vue'
import {
  changeChildrenObj
} from "@/views/eqpt/maintenanceRecords/config/filters";
export const mapOptions: FilterItem[] = [
  {
    label: '区域：', // 后续由接口获取下拉数据
    prop: 'regions',
    type: 'checkbox',
    span: 10,
    defaultValue: [],
    inputProps: {
      showCheckAll: true,
      options: [
        // { label: '区域A', value: "区域1", alert: true },
        // { label: '区域B', value: "区域2" },
        // { label: '区域C', value: "区域3" }
      ]
    },
    events: {
      change: (value: any, evt: any) => {
      }
    }
  },
  {
    label: '设备编号：',
    prop: 'eqptCode',
    type: 'input',
    span: 5,
    inputProps: {
      clearable: true,
      placeholder: '请输入设备编号'
    }
  },
  {
    label: '航站楼：', // 后续由接口获取下拉数据
    prop: 'terminal',
    type: 'checkbox',
    span: 6,
    defaultValue: [],
    inputProps: {
      options: []
    },
    events: {
      change: (value: any, evt: any) => {
      }
    }
  }
]

export const dialogOptions: FilterItem[] = [
  {
    label: '设备编号：',
    prop: 'eqptCode',
    type: 'input',
    span: 12,
    inputProps: {
      clearable: true,
      placeholder: '请输入设备编号'
    }
  },
  {
    label: '归属单位：',
    filterable: true,
    prop: 'owner',
    type: 'treeSelect',
    span: 12,
    inputProps: {
      'default-expand-all': true,
      options: []
    },
    events: {
      change: (value: any, evt: any) => {
        const params = ref({
          groupIds: [] as any
        })
        params.value.groupIds.length = 0
        params.value.groupIds.push(value)
        getUserInfo(params.value).then((resp) => {
          const ExecutorData = ref([]) as any
          resp.data.forEach((d: any) => {
            const option = ref({
              label: d.userName,
              value: d.userName,
              id: d.userId
            })
            ExecutorData.value.push(option.value)
          })
          evt.setFieldsValue({ maintainer: '' })
          evt.setOptions('maintainer', ExecutorData.value)
        })

        const paramName = {
          pageNum: 1,
          pageSize: 5000,
          condition: {
            owners: params.value.groupIds
          }
        }
        getFindDeviceTypeTree(paramName).then((res: any) => {
          evt.setFieldsValue({ typeId: '' })
          changeChildrenObj(res.data.list)
          console.log(res.data.list)
          dialogOptions[5].inputProps.data = res.data.list
        })
      }
    }
  },
  {
    label: '设备型号：',
    prop: 'eqptModel',
    type: 'input',
    span: 12,
    inputProps: {
      clearable: true,
      placeholder: '请输入设备型号'
    }
  },


  {
    label: '设备名称：',
    prop: 'eqptName',
    type: 'input',
    span: 12,
    inputProps: {
      clearable: true,
      placeholder: '请输入设备名称'
    }
  },
  {
    label: '使用部门：',
    filterable: true,
    prop: 'useOrgans',
    type: 'select',
    defaultValue: [],
    multiple: true,
    span: 12,
    inputProps: {
      'default-expand-all': true,
      options: []
    },
    events: {
      change: (value: any, evt: any) => {
      }
    }
  },

  {
    label: '设备类型：',
    filterable: true,
    prop: 'eqptType',
    type: 'treeSelect',
    span: 12,
    defaultValue: [],
    inputProps: {
      'default-expand-all': true,
      data: [],
      defaultProps: {}
    },

    events: {
      change: (value: any, evt: any) => {
      }
    }
  },

  {
    label: '位置：',
    prop: 'position',
    type: 'input',
    span: 12,
    inputProps: {
      clearable: true,
      placeholder: '请输入位置'
    }
  },
  {
    label: '地图坐标：',
    prop: 'coordinate',
    type: 'inputBtn',
    isDisabled: true,
    defaultValue: null,
    span: 12,
    icon: 'Location',
    inputProps: {
      clearable: true,
      placeholder: '请输入地图坐标'
    },
    events: {
      click: (value: any, evt: any) => {

      }
    }
  },
  {
    label: '区域：',
    prop: 'region',
    type: 'input',
    isDisabled: true,
    span: 12,
    inputProps: {
      clearable: false,
      placeholder: '根据地图坐标回显'
    }
  }
]
